package com.kudian.restful.controller;

import com.kudian.restful.service.AdService;
import com.kudian.restful.service.LoginSessionService;
import com.kudian.restful.service.WelInfoService;
import com.kudian.restful.vo.ad.AdItemVO;
import com.kudian.restful.vo.ad.CarouselRetVO;
import com.kudian.restful.vo.ad.MidAdRetVO;
import com.kudian.restful.vo.ad.MidAdVO;
import com.kudian.restful.vo.welinfo.WelInfoPageRetVO;
import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2016/4/27.
 */
@RestController
@RequestMapping("ad")
public class AdController {

    private static final Logger logger = Logger.getLogger(AdController.class);

    @Autowired
    private AdService adService;

    @Autowired
    private LoginSessionService loginSessionService;

    @RequestMapping(value = "carousel", method = RequestMethod.GET)
    @ApiOperation(value = "取得轮播广告", httpMethod = "GET", notes = "取得轮播广告", response = WelInfoPageRetVO.class)
    public @ResponseBody CarouselRetVO carousel() {
        CarouselRetVO o = new CarouselRetVO();

        try {
            o.setItems(adService.carousel());
            o.setErrcode(0);
            o.setErrmsg("成功取得轮播广告");
        } catch (Exception e) {
            o.setErrcode(9999);
            o.setErrmsg("取得轮播广告失败");
            logger.error(e);
        }
        return o;
    }

    /**
     * 取得中间广告
     */
    @RequestMapping(value = "queryMidAd", method = RequestMethod.POST)
    @ApiOperation(value = "取得中间广告", httpMethod = "POST", notes = "取得中间广告", response = MidAdRetVO.class)
    public @ResponseBody MidAdRetVO queryMidAd(@RequestBody MidAdVO vo) {
        MidAdRetVO o = new MidAdRetVO();
        try {
            o = adService.queryMidAd(vo);
            o.setErrcode(0);
            o.setErrmsg("成功取得中间广告");
        } catch (Exception e) {
            o.setErrcode(9999);
            o.setErrmsg("取得中间广告失败");
            logger.error(e);
        }
        return o;
    }
}
